package com.ttpark.DubboServerB;

import io.opentracing.contrib.apache.http.client.TracingHttpClientBuilder;
import io.opentracing.util.GlobalTracer;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableDubbo(scanBasePackages = {"com.ttpark.DubboServerB.service"})
public class DubboServerBApplication {

    public static void main(String[] args) {
        SpringApplication.run(DubboServerBApplication.class, args);
    }

    @Bean
    public HttpClient httpClient() {
        RequestConfig defaultRequestConfig = RequestConfig.custom()
                .setSocketTimeout(2000)
                .setConnectTimeout(3000)
                .setConnectionRequestTimeout(3000)
                .build();
        PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
        connManager.setMaxTotal(100);
        connManager.setDefaultMaxPerRoute(10);
        HttpClient httpClient =  TracingHttpClientBuilder.create().withTracer(GlobalTracer.get())
                .setDefaultRequestConfig(defaultRequestConfig)
                .setConnectionManager(connManager)
                .build();
        return httpClient;
    }
}
